package myapp.mvc_pattern;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

import android.util.Log;

public class Person extends Observable implements Serializable {

	private List<Item> itemList;
	private String vName;
	private MonthlyItem mItem;
		
	public Person (String n) {
		this.vName = n;
		this.itemList = new ArrayList<Item>();
		this.mItem = new MonthlyItem("Monatsbeitrag", 2,1);
		itemList.add(mItem);
	}
	
	public List<Item> getList () {
		return this.itemList;
	}
	
	public void addItemToList (Item item) {
		this.itemList.add(item);
		setChanged();
		notifyObservers();
	}
	
	public Item getSelectedItem (int pos) {
		Item selectedItem = itemList.get(pos);
		return selectedItem;
	}
	
	public void setList (List<Item> list) {
		itemList = list;
	}
	
	public String getName () {
		return vName;
	}
	
	public Integer getSumOpenItems () {
		int sum = 0;
		for (int i = 0; i < itemList.size(); i++) {
			if (itemList.get(i).getState() == false) {
				sum = sum + itemList.get(i).getPrize();
			}
		}
		return sum;
	}
	
	public Integer getNumOpenItems () {
		int count = 0;
		for (int i = 0; i < itemList.size(); i++) {
			if (itemList.get(i).getState() == false) {
				count++; 
			}
		}
		return count;
	}
	
	@Override
	public String toString () {
		return vName+"\t "+getNumOpenItems()+"\tOffene Strafen";
	}
	
}
